<?php
/**
 * Created by 784855684@qq.com.
 * Link: https://github.com/lichtung/inframe
 * User: linzh
 * Date: 6/25/17
 * Time: 5:15 PM
 */



namespace inframe\helper\traits;


trait Singleton
{
    /**
     * @param array ...$params
     * @return object
     */
    public static function getInstance(...$params)
    {
        static $_instances = [];
        $classname = static::class;
        $key = $params ? md5($classname . '###' . serialize($params)) : '_default_';
        isset($_instances[$key]) or $_instances[$key] = $params ? (new \ReflectionClass($classname))->newInstanceArgs($params) : new $classname();
        return $_instances[$key];
    }

}